package edu.whu.rose.clock.ssql.binding;

import java.util.ArrayList;

import com.sleepycat.bind.tuple.TupleBinding;
import com.sleepycat.bind.tuple.TupleInput;
import com.sleepycat.bind.tuple.TupleOutput;

import edu.whu.rose.clock.kps.algorithm.blinks.index.VertexDistance;

public class VertexDistanceBinding extends TupleBinding {

	public Object entryToObject(TupleInput input) {
		int size = input.readInt();
		VertexDistance[] list = new VertexDistance[size];
		for (int i = 0; i < size; i++) {
			int vertex = input.readInt();
			int distance = input.readInt();
			list[i] = new VertexDistance(vertex, distance);
		}
		return list;
	}
	
	public void objectToEntry(Object object, TupleOutput output) {
		ArrayList<VertexDistance> gii = (ArrayList<VertexDistance>)object;
		output.writeInt(gii.size());
		for (int i = 0; i < gii.size(); i++) {
			output.writeInt(gii.get(i).getVertex());
			output.writeInt(gii.get(i).getDistance());
		}
	}

}
